package com.xy.controller.uc;


import com.xy.common.base.ApiBaseResponse;
import com.xy.common.base.BaseController;
import com.xy.entity.product.Product;
import com.xy.entity.uc.FeedBack;
import com.xy.repository.FeedBackRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "意见反馈controller",description = "意见反馈")
@RestController
@RequestMapping(value = "api/feedback")
public class FeedBackController extends BaseController{

    @Autowired
    private FeedBackRepository feedBackRepository;

    @ApiOperation("获取所有意见反馈")
    @PostMapping("/allFeedback")
    @ResponseStatus(HttpStatus.OK)
    public ResponseEntity<?> allFeedback () {

        initBaseInfo();

        List<FeedBack> feedBackList = feedBackRepository.findAllByUserId(userId);

        return ResponseEntity.ok(ApiBaseResponse.fromHttpStatus(HttpStatus.OK, feedBackList));

    }


    @ApiOperation("提交意见反馈")
    @PostMapping("/feedback")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="advice",value = "意见内容",required=true),
            @ApiImplicitParam(name ="phone",value = "联系号码",required=false)
    })
    @ResponseStatus(HttpStatus.OK)
    public ResponseEntity<?> addFeedback (@RequestBody FeedBack feedBack) {
        initBaseInfo();
        feedBack.setUserId(userId);
        feedBackRepository.save(feedBack);
        return ResponseEntity.ok(ApiBaseResponse.fromHttpStatus(HttpStatus.OK));

    }


}
